package dao.impl;

import dao.IAdminDao;
import pojo.Admin;
import util.DBConn;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class AdminDaoImpl implements IAdminDao {

	private Connection conn = null;
	private PreparedStatement ps;
	String url = "jdbc:mysql://localhost:3306/javaeelab";
	//返回登录用户信息
	public Admin checkUser(Admin admin) throws Exception {
		conn= DBConn.getConnection(url);
		String sql = "select * from tb_admin where account=? and password=?";
		ps=conn.prepareStatement(sql);
		ps.setString(1, admin.getAccount());
		ps.setString(2, admin.getPassword());
		ResultSet rs=ps.executeQuery();
		Admin resultUser=null;
		if (rs.next()) {
			resultUser=new Admin();
			resultUser.setAccount(rs.getString("account"));
			resultUser.setPassword(rs.getString("password"));
		}
		return resultUser;
	}
}
